<template>
  <div class="shopcar-container">
    <div class="goods-list">
      <div class="mui-card">
        <div class="mui-card-content" v-for="item in shopgoods" :key="item.id">
          <div class="mui-card-content-inner flex">
            <!-- 复选框 -->
            <div class="mui-input-row mui-checkbox mui-left">
              <label>&nbsp;</label>
              <input type="checkbox">
            </div>
            <!-- 中间商品图片 -->
            <img :src="item.image">
            <!-- 右侧部分 -->
            <div class="info">
              <h1>{{ item.name }}</h1>
              <p class="flex">
                <span class="price">¥{{ item.price }}</span>
                <numbox :size='small' @count="updateCount" :initcount="getGoodsCount[item.id]" :max="item.num" :goodid="item.id"></numbox>
                <a href="#">删除</a>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapGetters } from 'vuex'
import numbox from '../components/numbox.vue'
export default {
  name: 'Shopcar',
  components: {
    numbox
  },
  data () {
    return {
      small: 'small',
      shopgoods: ''
    }
  },
  computed: {
    // 将他制作为computed的属性
    // car为制作名称
    ...mapState('shopcar', ['car']),
    ...mapGetters('shopcar', ['getGoodsCount'])
  },
  created () {
    this.getGoodList()
    console.log('....')
    console.log(this.getGoodsCount)
  },
  methods: {
    updateCount (newval) {
      console.log(newval)
      this.$store.commit('shopcar/updatecountInfo', newval)
    },
    getGoodList () {
      console.log(this.car)
      const arr = []
      this.car.forEach(item => {
        arr.push(item.id)
      })
      this.$http.get('shopcart', { params: { ids: arr } }).then(res => {
        console.log(res.data)
        this.shopgoods = res.data.data
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.flex {
  display: flex;
}
.shopcar-container {
  background: #eee;
  overflow: hidden;
  .goods-list {
    .mui-card-content-inner {
      align-items: center;
      padding: 10px;
      .mui-checkbox.mui-left input[type='checkbox'] {
        left: 0px;
      }
      .mui-radio.mui-left label,
      .mui-checkbox.mui-left label {
        padding-left: 20px;
        padding-right: 35px;
        padding-bottom: 22px;
      }
    }
    img {
      width: 60px;
    }
    .info {
      margin-left: 10px;
      width: 100%;
      overflow: hidden;
      box-sizing: border-box;
      h1 {
        font-size: 13px;
        font-weight: bold;
        line-height: 20px;
        padding-top: 10px;
      }
      p {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        .price {
          text-align: left;
          font-size: 16px;
          font-weight: 700;
          color: red;
          flex: 1;
        }
        a {
          line-height: 25px;
        }
      }
    }
  }
}
</style>
